<template>
  <div>
     <!-- 评论 -->
     <h3>发表评论</h3>
     <!-- <b v-if="type">你回复&nbsp;{{name}}</b> -->
     <textarea name="" value="请填写评论内容" v-model="commentText"></textarea>
     <button class="btn" @click="addComment">发表</button>
     <button class="btn" @click="canelComment">取消</button>
     <button class="btn" @click="testMsg">测试:消息传递到父，兄弟组件</button>
  
     <van-button type="primary">主要按钮</van-button>
    </div>
</template>

<script>
import bus from '../utils/bus'
import { Button } from 'vant';


 export default {
   data () {
     return {
      commentText:''
     }
   },
   created(){
     
   },

   methods: {
        addComment: function() {
            console.log("addComment: " + this.commentText);
            //this.$parent.$emit("submit-comment",this.commentText);
            
            // {
            //     name: '早起的鸟儿有食吃',
            //     time: '2021-02-18',
            //     content: '希望有朝一日我也能向你一样',
            //     reply:[]
            // }
            var commentObject={
                   name:"隔壁老王",
                   time:'',
                   content:'',
                   reply:[]
            };

    
            commentObject.time = this.getDateString();
            commentObject.content = this.commentText;
   
            bus.$emit('submit-comment',commentObject);

            //this.commentText = "";

        },
        canelComment: function() {
            this.$emit("canel");
            this.commentText = "";
        },

         getDateString(){
            var date=new Date;
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            m = m < 10 ? '0' + m : m
            var d = date.getDate()
            d = d < 10 ? ('0' + d) : d
            return  y + '-' +m +'-' +d;
        },
        testMsg(){
          console.log("test msg");
          this.$emit('msg-child-change', '我来自子组件');



        }
   }
 }
</script>

<style scoped>

 
</style>
